package com.raowb.common.rest;

import java.util.HashMap;
import java.util.Map;

import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 返回数据
 *
 * @author RaoWenbiao
 * 
 * @date 2016年10月27日 下午9:59:27
 */
public class RestResult extends AjaxResult {
	private static final long serialVersionUID = 1L;

	public RestResult() {
		put("code", "1");
	}

	public static RestResult error() {
		return error("500", "未知异常，请联系管理员");
	}

	public static RestResult error(String msg) {
		return error("500", msg);
	}

	public static RestResult error(String code, String msg) {
		RestResult r = new RestResult();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static RestResult success(String msg) {
		RestResult r = new RestResult();
		r.put("msg", msg);
		return r;
	}

	public static RestResult success(Map<String, Object> map) {
		RestResult r = new RestResult();
		r.putAll(map);
		return r;
	}

	public static RestResult success(Object data) {
		return success().putData(data);
	}

	public static RestResult success() {
		return new RestResult();
	}
	@Override
	public RestResult put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public RestResult putData(Object data) {
		return put("data", data);
	}
}
